
/**
 * Created by wxnacy on 2015/8/12.
 */

$(function() {
    //cms系统的初始化
    initCMS();
    //初始化保存类方法
    initSave();
    //初始化数据
    initCMSData();

    /*$('[data-dismiss="modal"]').click(function(){
        $('div.modal-backdrop').remove();
    });*/

});

/**
 * 选择select时的改变的附加参数
 * @param $obj
 */

function changeSelect($obj){
    $obj.change(function(){
        var val = $(this).val();
        var text = $(this).find("option:selected").text()
        var id = $(this).attr('id');
        $('#'+id+'-name').val(text);

        var $modal = $('.modal');

        if($modal.hasClass('bgvideo-cms')){
            var source;
            var video_unique;
            $.get('/vrs/video/one/'+val+'.jsn',function(data,status){
                if(status == 'success'){
                    var success = data.success;
                    if(success){

                        source = data.data.source;
                        $.get('/vrs/api/getVideo.jsn?videoId='+source,function(data,status){
                            if(status == 'success'){
                                var code = data.code;
                                if(code ==0){
                                    video_unique = data.data.video_unique;
                                    var img = data.data.img;
                                    $('#'+id+'-foreignVid').val(source);
                                    $('#'+id+'-foreignUnique').val(video_unique);
                                    $('#'+id+'-pic').val(img);
                                }else{
                                    //返回数据有误
                                }
                            }else{
                                //调取接口失败
                            }
                        });
                    }else{
                        //返回数据有误
                    }
                }else{
                    //接口调取失败
                }

            });


        }

        //console.log($('#'+id+'-name').val());
    });
}


/**
 * 初始化数据
 */
function initCMSData(){
    //专辑列表
    initAlbumSelectData();
    //type列表数据
    //initTypeSelectData();
    //分类数据
    //initCategorySelectData();
}
/**
 * 初始化type列表数据
 */
function initCategorySelectData(){
    $.get("/scripts/cms/category.json",function(data,textStatus){
        //data     返回的内容，xml,json,html文档
        //textStatus     请求状态：success/error/notmodified/timeout
        if(textStatus == "success"){
            var success = data.success;
            if(success){
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(data.data,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.id+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="categorySelect" required data-placeholder="请选择分类" class="chosen w150" name="category">'+optionList.join()+'</select>');
                var $select =  $('#categorySelect');
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
            }
        }
    },"json");
}
/**
 * 初始化type列表数据
 */
function initTypeSelectData(){
    $.get("/scripts/cms/type.json",function(data,textStatus){
        //data     返回的内容，xml,json,html文档
        //textStatus     请求状态：success/error/notmodified/timeout
        if(textStatus == "success"){
            var success = data.success;
            if(success){
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(data.data,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.id+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="typeSelect" data-placeholder="请选择类型" class="chosen col-xs-6" name="type">'+optionList.join()+'</select>');
                var $select =  $('#typeSelect');
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
            }
        }
    },"json");
}
/**
 * 初始化专辑列表数据
 */
function initAlbumSelectData(){
    $.get("/vrs/album/listAll.jsn?isdisplay=1",function(data,textStatus){
        //data     返回的内容，xml,json,html文档
        //textStatus     请求状态：success/error/notmodified/timeout
        if(textStatus == "success"){
            var success = data.success;
            if(success){
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(data.data,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.albumId+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="albumIdSelect" required data-placeholder="请选择专辑" class="chosen w200" name="albumId">'+optionList.join()+'</select>');
                var $select =  $('#albumIdSelect');
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
                initSelectAbumId();
            }
        }
    },"json");
}

/**
 * ott轮播数据加载
 * @param id
 * @param data
 */
function initEditOttList($obj,data){
    data = $.evalJSON(data);
    //console.log(data);
    var rows = data.rows;
    var $ul = $("ul",$obj);
    var $newLi = $("li:first",$obj).clone(true);
    $ul.children().remove();
    //var $div = $('div.hd span:first',$obj);
    $.each(rows,function(i,item){
        $newLi = $newLi.clone(true);
        $newLi.find('img').attr('src',item.pic);
        $newLi.attr('video-id',item.videoId);
        playVideo($newLi);
        $ul.append($newLi);
    })
    //$li.remove();
    $("li",$ul).each(function(i){
        $(this).attr("data-plth",i+1);
    });
    $obj.myFocus({
        picHeight:180,            //中间大图 高
        picWidth:320,            //中间大图 宽
        scale:0.8,               //缩小比例
        pitch:45				 //图与图 间隔
    });
}



/**
 * 背景视频修改列表的展示
 * @param $obj
 * @param data
 */
function initEditBackgroundList($obj,data){
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    var $ul = $obj;
    $.each(rows,function(i,item){
        var $liHtml = $(editLiHtml);
        $liHtml.find('img').attr('src',item.pic);
        $liHtml.find('input.data-json').val($.toJSON(item));


        $ul.append($liHtml);
    })
    $ul.find('li:first').remove();
}
/**
 * 排行榜修改列表的展示
 * @param $obj
 * @param data
 */
function initEditRankList($obj,data){
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    var $ul = $obj;
    $.each(rows,function(i,item){
        var $liHtml = $(editLiHtml);
        $liHtml.find('img').attr('src',item.standardPic[0].url);
        $liHtml.find('input.data-json').val($.toJSON(item));

        ////弹出窗口
        //initOpenModal($liHtml.find('[data-toggle="modal"]'));
        ////删除功能
        //initDelete($liHtml.find('.focus-remove'));

        $ul.append($liHtml);
    })
    $ul.find('li:first').remove();
}



/**
 * 修改时,修改区下拉图片列表的显示
 * @param id
 * @param data
 */
function initEditIndexList(id,data,category){
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    var $ul = $('#'+id);
    $.each(rows,function(i,item){
        var $liHtml = $(editLiHtml);
        $liHtml.find('img').attr('src',item.pic);
        $liHtml.find('input.data-json').val($.toJSON(item));
        //弹出窗口
        initOpenModal($liHtml.find('[data-toggle="modal"]'));
        //删除功能
        initDelete($liHtml.find('.focus-remove'));
        //显示角标
        var $div = $liHtml.find('.gory');
        if(item.category != '0'){
            $.each(category.data,function(i,cate){
                if(item.category == cate.id){
                    $div.find('div').text(cate.name);
                    $div.css({"background":cate.color});
                }
            })
        }else{
            $div.remove();
        }
        $ul.append($liHtml);
    })
    $ul.find('li:first').remove();
}



/**
 * 下拉图片列表的预览
 * @param $ul
 * @param data
 * @param category
 */
function initPreviewMobileList($ul,data,category){
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    $ul.children().remove();
    $.each(rows,function(i,item){
        var $liHtml = $(liHtml);
        $liHtml.find('img').attr('src',item.pic);
        $liHtml.attr('video-id',item.videoId);
        playVideo($liHtml);
        //显示角标
        var $div = $liHtml.find('.gory');
        if(item.category != '0'){
            $.each(category.data,function(i,cate){
                if(item.category == cate.id){
                    $div.find('div').text(cate.name);
                    $div.css({"background":cate.color});
                }
            })
        }else{
            $div.remove();
        }
        $ul.append($liHtml);
    })
}

/**
 * 显示背景视频预览区域
 * @param $ul
 * @param data
 */
function initPreviewBackgroundList($ul,data){
    //console.log($ul,data);
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    $ul.children().remove();
    $.each(rows,function(i,item){
        var $liHtml = $(previewLiHtml);
        $liHtml.find('img.cms-preview-image').attr('src',item.pic);
        $liHtml.attr('video-id',item.videoId);
        playVideo($liHtml);
        $ul.append($liHtml);
    })
}
/**
 * 显示排行榜预览区域
 * @param $ul
 * @param data
 */
function initPreviewRankList($ul,data){
    //console.log($ul,data);
    if(data == ''){
        return;
    }
    data = $.evalJSON(data);
    var rows = data.rows;
    console.log('preview rows',rows);
    $ul.children().remove();
    $.each(rows,function(i,item){
        var $liHtml = $(previewLiHtml);
        $liHtml.find('img').attr('src',item.standardPic[0].url);
        $liHtml.find('p[title="videoName"]').text(item.videoName);
        $liHtml.find('p[title="starringName"]').text(item.starringName);
        $liHtml.find('span[title="viewCount"]').text(item.viewCount);
        $liHtml.attr('video-id',item.videoId);
        playVideo($liHtml);
        $ul.append($liHtml);
    })
}
/**
 * 修改时轮播图数据加载
 * @param id
 * @param data
 */
function initEditHead(id,data){
    if(data == ''){
        return;
    }
    var $head = $('#'+id);
    var $ol = $head.find('ol.carousel-indicators');
    var $div = $head.find('div.carousel-inner');
    data = $.evalJSON(data);
    var rows = data.rows;
    $.each(rows,function(i,item){
        var $olHtml = $(olHtml);
        var $divHtml = $(divHtml);

        $olHtml.attr('data-slide-to',i);
        $ol.append($olHtml);

        $divHtml.find('img').attr('src',item.pic);
        $divHtml.find('p:first').text(item.name);
        $divHtml.find('input.data-json').val($.toJSON(item));
        //弹出窗口
        //initOpenModal($divHtml.find('[data-toggle="modal"]'));
        //删除功能
        //initDelete($divHtml.find('.focus-remove'));
        $div.append($divHtml);
    });
    $ol.find('li:first').remove();
    $ol.find('li:not(:eq(0))').removeClass('active');
    $div.find('div:first').remove();
    $div.find('div:not(:eq(0))').removeClass('active');
}

/**
 * mobile端头图预览方法
 * @param $obj
 * @param data
 */
function initPreviewMobileHead($head,data){
    if(data == {} || data == ''){
        return;
    }
    var $ol = $head.find('ol.carousel-indicators');
    var $div = $head.find('div.carousel-inner');
    data = $.evalJSON(data);
    var rows = data.rows;
    $ol.children().remove();
    $div.children().remove();

    $.each(rows,function(i,item){
        var $olHtml = $(olHtml);
        var $divHtml = $(divHtml);

        $olHtml.attr('data-slide-to',i);
        $ol.append($olHtml);

        $divHtml.find('img').attr('src',item.pic);
        $divHtml.find('p:first').text(item.name);
        $divHtml.find('input.data-json').val($.toJSON(item));
        $divHtml.attr('video-id',item.videoId);
        playVideo($divHtml);
        $div.append($divHtml);
    });
    $ol.children(':not(:eq(0))').removeClass('active');
    $div.children(':not(:eq(0))').removeClass('active');
}

/**
 * 初始化保存类方法
 */
function initSave(){


    $('.save-focus').click(function(){
        var flag = false;
        var array = new Array();
        var $form = $('#'+$(this).data('id'));
        $form.find('input.data-json').each(function(i){
            var json = $(this).val();
            //判断有空就不提交
            if(json.length==0){
                flag = true;
                return;
            }
            json = $.evalJSON(json);
            array[i]=json;
        })
        if(flag){
            var msg = '数据不完整，不能提交';
            var type = 'error';
            var $layout = 'topRight';
            notyRestart(msg,type,$layout);
            return;
        }
        var data = {total:array.length,rows:array};
        data = $.toJSON(data);
        $form.find('input[name="focus.data"]').val(data);
        $form.ajaxSubmit(function(data){
            var success = data.success;

            if(success){
                swal({
                    title: data.msg,
                    text: '点击返回',
                    type:'success'
                });
            }else{
                swal({
                    title: data.msg,
                    text: '点击返回',
                    type:'error'
                });
            }
        });
    })
}



/**
 * cms系统的初始化
 */
var previewLiHtml = $('ul.cms-preview-list li:first').clone(true).prop('outerHTML');//预览列表元素
var editLiHtml = $('ul.cms-edit-list li:first').clone(true).prop('outerHTML');//预览列表元素
var liHtml = $('ul.sortable-list li:first').clone(true).prop('outerHTML');//列表元素
var olHtml = $('ol.carousel-indicators li:first').clone(true).prop('outerHTML');//轮播ol元素
var divHtml = $('div.carousel-inner div:first').clone(true).prop('outerHTML');//轮播div元素
function initCMS(){
    //添加列表按钮
    var $addBut = $('.add');
    $addBut.click(function(){
        var $liHtml = $($('ul.cms-edit-list li:first').clone(true).prop('outerHTML'));
        $liHtml.find('img').attr('src','/images/upload_1242x416.jpg');
        $liHtml.find('input.data-json').val();
        //弹出窗口
        initOpenModal($liHtml.find('[data-toggle="modal"]'));
        //删除功能
        initDelete($liHtml.find('.focus-remove'));
        $(this).parent().prev().find('ul').prepend($liHtml);

    })
    //添加轮播图按钮
    var $addHeadBut = $('.add-head');
    $addHeadBut.click(function(){
        var $olHtml = $(olHtml);
        var $divHtml = $(divHtml);
        var dataTo = $('ol.carousel-indicators li:first').attr('data-slide-to');
        dataTo = parseInt(dataTo)+1;
        $('div.carousel-inner div').removeClass('active');
        $('ol.carousel-indicators li').removeClass('active');
        $('#carousel-example-generic').find('ol').prepend($olHtml.attr('data-slide-to',dataTo));
        //弹出窗口
        initOpenModal($divHtml.find('[data-toggle="modal"]'));
        //删除功能
        initDelete($divHtml.find('.focus-remove'));
        $('#carousel-example-generic').find('div.carousel-inner').prepend($divHtml);
        //将其他的元素index递增
        $('ol.carousel-indicators li').each(function(i){
            $(this).attr("data-slide-to",i);
        })
    })
    //弹出窗口
    initOpenModal($('[data-toggle="modal"]'));
    //处理弹出框的保存操作
    $('button.save').click(function(){
        var $this = $(this);
        var $modal = $('.modal');


        var $form = $('#modalForm');
        var data = $form.serializeArray();
        var jsonHtml = '{';
        $.each(data,function(i,item){
            if(item.name != 'root'){
                jsonHtml = jsonHtml+ '\"'+item.name+'\":\"'+item.value+'\",'
            }
        })
        //获取上传后的图片
        var pic = $form.find('img[data-theme-name="view-image"]').attr('src');
        var name = $form.find('input[name="name"]').val();
        var $openModal = $('.openModal');
        if($modal.hasClass('mRank')){
            var standardPic = getPicJson();
            var array = $.toJSON($.evalJSON(standardPic).data);
            jsonHtml = jsonHtml + '"standardPic":'+array;
            $openModal.find('p[title="videoName"]').text($form.find('input[name="videoName"]').val());
            $openModal.find('p[title="starringName"]').text($form.find('input[name="starringName"]').val());
            $openModal.find('p[title="viewCount"]').text($form.find('input[name="viewCount"]').val());
            console.log('rank')
        }else if($modal.hasClass('bgvideo-cms')){
            console.log('background');
            pic = $form.find('input[name="pic"]').val();
            jsonHtml = jsonHtml.substring(0,jsonHtml.lastIndexOf(','));
        }else if($modal.hasClass('video-detail')){
            jsonHtml = jsonHtml + '"img":"'+pic+'"';
        }else if($modal.hasClass('video-detail-ott')){
            jsonHtml = jsonHtml.substring(0,jsonHtml.lastIndexOf(","))
        }else{
            jsonHtml = jsonHtml + '"pic":"'+pic+'"';
        }
        jsonHtml = jsonHtml + '}';
        console.log(jsonHtml);
        //jsonHtml = jsonHtml.substring(0,jsonHtml.lastIndexOf(","))
        $openModal.find('input.data-json').val(jsonHtml);

        $openModal.find('img').attr('src',pic);
        $openModal.find('p:first').text(name);
    })
    //选中专辑的效果
    initSelectAbumId();

    //初始化删除功能
    initDelete($('.focus-remove'));
}
/**
 * 初始化删除功能
 * @param $remove
 */
function initDelete($remove){
    $remove.click(function(){
        var $parent = $(this).parent();
        console.log($parent.siblings().length);
        if($parent.siblings().length==0){
            var msg = '最后一个不能删除';
            var type = 'error';
            var $layout = 'topRight';
            notyRestart(msg,type,$layout);
            return;
        }

        swal({
            title: '确认此操作吗?',
            //text: 'You will not be able to recover this imaginary file!',
            type: 'warning',
            showCancelButton: true,
            //confirmButtonColor: '#DD6B55',
            confirmButtonText: '确定!',
            closeOnConfirm: true,
            cancelButtonText:'取消'
        },function() {

            if ($parent.hasClass("item")) {
                var $ol = $(this).parent().parent().prev("ol");

                var index = $(this).parent().prevAll().length;

                var $greadParent = $parent.parent();
                $ol.find(':eq(' + index + ')').remove();

                $parent.remove();

                //显示后边的数据
                $ol.find('li:first').addClass("active");
                $greadParent.find('div:first').addClass("active");

                $('ol.carousel-indicators li').each(function (i) {
                    $(this).attr("data-slide-to", i);
                })
            } else {
                $parent.remove();
            }
        });
        //var $ol = $(this).parent().parent().prev("ol");
        //if($ol.length>0){
        //    var index = $(this).parent().parent().indexOf($(this).parent());
        //    console.log(index);
        //    $ol.find(':eq('+index+')').remove();
        //}
    }).mouseenter(function(){
        $(this).show();
    }).mouseleave(function(){
        $(this).hide();
    });
}
/**
 * 选中专辑的效果
 */
function initSelectAbumId(){
    $('#albumIdSelect').change(function(){
        changeVideoByAlbum($(this),'','');
        changeStarrByAlbum($(this),'','');
    });

}
/**
 * 通过改变专辑来改变视频内容
 * @param $album
 */
function changeVideoByAlbum($album,id,videoId){
    var value = $album.val();
    var url = "/vrs/video/listJson.jsn?video.album.albumId="+value+"&isdisplay=1";
    if(value == ''){
        return;
    }
    $.ajax({
        type: "get",
        dataType: "json",
        url: url,
        error: function () {

        },
        success: function (data) {
            var success = data.success;
            if(success){
                var rows = data.data.rows;
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(rows,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.videoId+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="videoIdSelect" required data-placeholder="请选择视频" class="chosen w150" name="videoId">'+optionList.join()+'</select>');
                var $select =  $('#videoIdSelect');
                $newSelect.addClass($select.attr('class'));
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
                //$select.next().css({"width":"150px"});
                if(videoId != ''){
                    initEditSelect(id,videoId);
                }
                changeSelect($('#videoIdSelect'));
            }
        }
    });
}

/**
 * 通过改变专辑改变艺人列表
 * @param $album
 * @param selectId
 * @param starrId
 */
function changeStarrByAlbum($album,selectId,starrId){
    var value = $album.val();
    var url = "/vrs/album/one.jsn?albumId="+value;
    if(value == ''){
        return;
    }
    $.ajax({
        type: "get",
        dataType: "json",
        url: url,
        error: function () {

        },
        success: function (data) {
            var success = data.success;
            if(success){
                var rows = $.evalJSON(data.data.starringInfo).data;
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(rows,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.starringId+'">'+item.name+'</option>';
                });
                var $newSelect =  $('<select id="starrIdSelect" required data-placeholder="请选择艺人" class="chosen w150" name="objectId">'+optionList.join()+'</select>');//$($('#starrIdSelect').clone(true).prop('outerHTML')); //
                var $select =  $('#starrIdSelect');
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
                //$select.next().css({"width":"150px"});
                if(selectId != ''){
                    initEditSelect(selectId,starrId);
                }
                changeSelect($('#starrIdSelect'));
            }
        }
    });
}


/**
 * 初始化弹出窗口
 * @param $modal
 */
function initOpenModal($openModal){
    var $modal = $('.modal');
    $openModal.mouseenter(function(){
        //$(this).stop().animate({"left":"-40px"})
        $(this).next('.focus-remove').show();
    }).mouseleave(function(){
        //$(this).stop().animate({"left":"0"})
        $(this).next('.focus-remove').hide();
    }).click(function(){
        console.log(0);
        var _target = $(this).data('target');
        if(_target==".play-video" || _target == ".address-modal" || _target==".play-audio"){
            return;
        }
        if(_target == ".video-detail-preview"){
            var $this =  $(this);
            var $form = $this.parents('form');
            var data = getDetailData($form);
            $("#previewIframe")[0].contentWindow.startinit($.evalJSON(data));
            return;
        }
        if(_target == ".video-detail-ott-preview"){
            var $this =  $(this);
            var $form = $this.parents('form');
            var data = getDetailData($form);
            $("#previewIframe")[0].contentWindow.getDate(data);
            return;
        }
        //区分弹出框口
        $('[data-toggle="modal"]').removeClass('openModal');
        $(this).addClass('openModal');
        //console.log($(this).prop("outerHTML"));
        //弹出框内的样式调整

        //$modal.find('.chosen').next().css({"width":"150px"});
        $modal.find('img[data-theme-name="view-image"]').css({"width":$(this).find('img').width(),"height":$(this).find('img').height()})
        //弹出框填充数据准备中
        var data = $(this).find('input.data-json').val();
        if(data != ''){
            data = $.evalJSON(data);
            //弹出框填充数据
            if($modal.hasClass('mRank')){//排行榜的数据展示
                var $picDiv = $('#picDiv');//图片组件
                $modal.find('[data-theme-name="terminal"]').next().css({"width":"100px"});
                $modal.find('input[name="name"]').val(data.name);
                $modal.find('input[name="viewCount"]').val(data.viewCount);
                $modal.find('input[name="videoName"]').val(data.videoName);
                $modal.find('input[name="starringName"]').val(data.starringName);
                $picDiv.find('div[data-theme-name="upload-image-div"]:gt(0)').remove();
                initEditPic('picDiv', $.toJSON(data));
                $picDiv.find('button[data-theme-name="remove-upload-image"]').each(function(){
                    initUploadImageRemove($(this));
                });

                //$modal.find('img[data-theme-name="view-image"]').attr('src',data.pic);
                initEditSelect('albumIdSelect',data.albumId);
                initEditSelect('typeSelect',data.type);
                changeVideoByAlbum($('#albumIdSelect'),'videoIdSelect',data.videoId);
                changeStarrByAlbum($('#albumIdSelect'),'starrIdSelect',data.objectId);

            }else if($modal.hasClass('bgvideo-cms')){//背景视频
                $modal.find('input[name="foreignVid"]').val(data.foreignVid);
                $modal.find('input[name="foreignUnique"]').val(data.foreignUnique);
                $modal.find('input[name="pic"]').val(data.pic);
                initEditSelect('albumIdSelect',data.albumId);
                changeVideoByAlbum($('#albumIdSelect'),'videoIdSelect',data.videoId);
            }else if($modal.hasClass('video-detail')){//直播详情页
                $modal.find('input[name="title"]').val(data.title);
                $modal.find('input[name="prize"]').val(data.prize);
                //$modal.find('input[name="iosType"]').val(data.iosType);
                $modal.find('img[name="img"]').attr('src',data.img);
                initEditSelect('videoIdSelect',data.videoId);
                initEditSelect('typeSelect',data.iosType);
                //changeVideoByAlbum($('#albumIdSelect'),'videoIdSelect',data.videoId);
            }else if($modal.hasClass('video-detail-ott')){//ott直播详情页
                $modal.find('input[name="videoName"]').val(data.videoName);
                initEditSelect('videoIdSelect',data.videoId);
            }else if($modal.hasClass('address')){//背景视频
                var domainName = getDomainName();
                var $mobile = $modal.find('input[name="mobile"]');
                var $ott = $modal.find('input[name="ott"]');
                if(domainName == 'media.zhengzai.tv'){

                }else if(domainName == 'media.zhengzai.tv:81' || domainName == '123.56.125.164:81' || domainName == 'test.zhengzai.tv'){
                    $mobile.val('http://182.92.167.30:89/h5pay/detail.html?albumId='+albumId);
                    //$ott.val('http://182.92.167.30:89/h5pay/detail.html?albumId='+albumId);
                }
            }else {//其他首页的数据展示
                $modal.find('input[name="name"]').val(data.name);
                $modal.find('input[name="url"]').val(data.url);
                $modal.find('img[data-theme-name="view-image"]').attr('src',data.pic);
                initEditSelect('typeSelect',data.type);
                initEditSelect('categorySelect',data.category);
                initEditSelect('albumIdSelect',data.albumId);
                changeVideoByAlbum($('#albumIdSelect'),'videoIdSelect',data.videoId);
                changeStarrByAlbum($('#albumIdSelect'),'starrIdSelect',data.objectId);

            }

        }
        $modal.find('.chosen').each(function(){
            console.log($(this).css("width"));
            var $this = $(this);
            var width = $this.css("width");
            $this.next().css("width",width);
        });

        // $('div.chosen-container').css({"width":"100px"});
    })
}